package com.drug.mingkang.service.impl;

import com.drug.mingkang.model.HqMarket;
import com.drug.mingkang.mapper.HqMarketMapper;
import com.drug.mingkang.model.vo.HqMarketVo;
import com.drug.mingkang.permission.model.vo.PerUsersVo;
import com.drug.mingkang.service.HqMarketService;
import com.drug.mingkang.utils.Tools;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 总公司销售(HqMarket)表服务实现类
 *
 * @author wenchangjian
 * @since 2020-08-11 12:00:13
 */
@Service("hqMarketService")
public class HqMarketServiceImpl implements HqMarketService {
    @Resource
    private HqMarketMapper hqMarketMapper;


    @Resource
    private Tools tools;
    /**
     * 通过ID查询单条数据
     *
     * @param marketId 主键
     * @return 实例对象
     */
    @Override
    public HqMarket queryById(String marketId) {
        return this.hqMarketMapper.queryById(marketId);
    }

    @Override
    public List<Integer> findTodaysSalesOrMonthSales(String i) {
        List<Integer> list1=new ArrayList<>();
        List<Integer> list;
        if ("0".equals(i)){
            list=this.hqMarketMapper.findTodayIncomeOrMonthIncomes();
        }else {
            list=this.hqMarketMapper.findTodayIncomeOrMonthIncomeA(i);
        }

        //判断 如果等于null就替换为0
        for (int j = 0; j < list.size(); j++) {
            if (list.get(j)==null){
                list.set(j, 0);
            }
        }
        //月收入
        list1.add(list.get(0));
        //日收入
        list1.add(list.get(1));
        return list1;
    }

    /**
     * 查询多条数据
     * @param hqMarketVo
     * @return 对象列表
     */
    @Override
    public Map<String, Object> queryAllByLimit(HqMarketVo hqMarketVo) {
        return tools.limit(this.hqMarketMapper.queryAllByLimit(hqMarketVo), this.hqMarketMapper.count(hqMarketVo));
    }



    /**
     * 新增数据
     *
     * @param hqMarket 实例对象
     * @return 实例对象
     */
    @Override
    public HqMarket insert(HqMarket hqMarket) {
        this.hqMarketMapper.insert(hqMarket);
        return hqMarket;
    }

    /**
     * 修改数据
     *
     * @param hqMarket 实例对象
     * @return 实例对象
     */
    @Override
    public HqMarket update(HqMarket hqMarket) {
        this.hqMarketMapper.update(hqMarket);
        return this.queryById(hqMarket.getMarketId());
    }

    /**
     * 通过主键删除数据
     *
     * @param marketId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String marketId) {
        return this.hqMarketMapper.deleteById(marketId) > 0;
    }



}